import matplotlib.pyplot as plt
import numpy as np

# 设置栅格大小
grid_size = 10

# 创建一个随机的栅格数据（范围在0到1之间）
grid = np.random.rand(grid_size, grid_size)

# 创建一个空的栅格，用于标记障碍物
obstacle_grid = np.zeros((grid_size, grid_size))

# 将障碍物位置标记为1（假设障碍物由多个格子组合而成）
obstacle_grid[2:5, 3:6] = 1  # 障碍物位置标记为1
obstacle_grid[7:9, 5:8] = 1  # 障碍物位置标记为1

# 创建一个新的图形
plt.figure(figsize=(8, 8))

# 绘制栅格图，设置透明度
plt.imshow(grid, cmap='gray', origin='upper', extent=[0, grid_size, 0, grid_size], alpha=0.5)

# 标记障碍物
for i in range(grid_size):
    for j in range(grid_size):
        if obstacle_grid[i, j] == 1:
            plt.fill_between([j, j+1], i, i+1, color='black')

# 绘制网格线
plt.grid(True, which='both', linestyle='-', color='black', linewidth=1)

plt.colorbar(label='Alpha')  # 添加透明度颜色条
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Grid Plot with Compdasdsadsadosite Obstacles')
plt.show()
a